<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账号id" prop="awemeId">
        <el-input
          v-model="queryParams.awemeId"
          placeholder="请输入账号id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="样品id" prop="productId">
        <el-input
          v-model="queryParams.productId"
          placeholder="请输入样品id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="选择日期">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-date-picker
              v-model="dateRange"
              type="daterange"
              align="left"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="handleDateChange"
              :picker-options="pickerOptions">
            </el-date-picker>
          </el-col>
          <el-col :span="1.5">
            <el-form-item style="">
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dr:base:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseList" @selection-change="handleSelectionChange">
      <el-table-column label="日期" align="center" prop="dayDate" />
      <el-table-column label="达人" align="center" prop="ownerTime" >
        <template #default="{row}">
          <!-- <span>{{ row.awemeId }}</span> -->
          <span style="white-space: pre-line;">{{ row.awemeName }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="关联其他表的uid" align="center" prop="unionUid" /> -->

      <el-table-column label="商品" align="center" prop="productId" >
        <template #default="{row}">
          <!-- <span>{{ row.productId }}</span> -->
          <span style="white-space: pre-line;">{{ row.productName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出单数量" align="center" prop="totalCount" />

    </el-table>
<!--     
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

  </div>
</template>

<script>
import { sellAnalysis } from "@/api/dr/sellDetails"

export default {
  name: "SellDetails",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 达人列页信息表格数据
      baseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dayDate: null,
        dayDateStart: null,
        dayDateEnd: null,
        awemeId: null,
        awemeName: null,
        productName: null,
        productId: null
        
      },
      dateRange: [],
      dayDateStart: null,
      dayDateEnd: null,
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        nickname: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList();
    this.initDateRange();
  },
  methods: {
    /** 查询销售数据信息列表 */
    getList() {
      this.loading = true
      sellAnalysis(this.queryParams).then(response => {
        // console.log(response.data)
        this.baseList = response.data
        // this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        awemeId: null,
        unionUid: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.dayDateStart = this.dayDateStart;
      this.queryParams.dayDateEnd = this.dayDateEnd;
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.awemeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 日期变化时更新dayDateStart和dayDateEnd字段
    handleDateChange(val) {
      if (val && val.length === 2) {
        this.dayDateStart = val[0]; // 开始时间赋值给dayDateStart
        this.dayDateEnd = val[1]; // 结束时间赋值给dayDateEnd
      } else {
        this.dayDateStart = null;
        this.dayDateEnd = null;
      }
    },
    // 如果已有 dayDateStart 和 dayDateEnd 值，初始化时设置dateRange
    initDateRange() {
      if (this.dayDateStart && this.dayDateEnd) {
        this.dateRange = [this.dayDateStart, this.dayDateEnd];
      }
    },
  
    /** 导出按钮操作 */
    handleExport() {
      this.download('dr/base/export', {
        ...this.queryParams
      }, `base_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
